//-----------------------------------------------------------------------
// <copyright file="Device.cpp" company="Microsoft">
//      Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// Module:
//      Device.cpp
//
// Description:
//
//-----------------------------------------------------------------------


#include "Common.h"

// Define defaults for Device Capabilities static members
bool     CDevice::m_fDeviceCapabilitiesAreDefined = false;
LPCWSTR  CDevice::m_pwszDeviceFriendlyName;
LPCWSTR  CDevice::m_pwszDeviceManufacturer;
LPCWSTR  CDevice::m_pwszDeviceFirmwareVersion;
DWORD    CDevice::m_dwDeviceHorizontalResolution = 0;
DWORD    CDevice::m_dwDeviceVerticalResolution = 0;
DWORD    CDevice::m_dwDeviceBitDepth = 0;
BOOL     CDevice::m_bTopDownBitmap = FALSE;

HRESULT CDevice::SetDeviceCaps(LPCWSTR pwszDeviceFriendlyName,
                               LPCWSTR pwszDeviceManufacturer,
                               LPCWSTR pwszDeviceFirmwareVersion,
                               DWORD dwDeviceHorizontalResolution,
                               DWORD dwDeviceVerticalResolution,
                               DWORD dwDeviceBitDepth,
                               BOOL bTopDownBitmap)
{
    HRESULT hr = S_OK;

    if (m_fDeviceCapabilitiesAreDefined)
    {
        ReleaseDeviceCaps();
    }
    
    m_pwszDeviceFriendlyName = _wcsdup(pwszDeviceFriendlyName);
    m_pwszDeviceManufacturer = _wcsdup(pwszDeviceManufacturer);
    m_pwszDeviceFirmwareVersion = _wcsdup(pwszDeviceFirmwareVersion);

    m_dwDeviceHorizontalResolution = dwDeviceHorizontalResolution;
    m_dwDeviceVerticalResolution = dwDeviceVerticalResolution;
    m_dwDeviceBitDepth = dwDeviceBitDepth;
    m_bTopDownBitmap = bTopDownBitmap;
    
    m_fDeviceCapabilitiesAreDefined = true;

    return hr;
}

HRESULT CDevice::ReleaseDeviceCaps(void)
{
    m_fDeviceCapabilitiesAreDefined = false;

    SAFE_FREE(m_pwszDeviceFriendlyName);
    SAFE_FREE(m_pwszDeviceManufacturer);
    SAFE_FREE(m_pwszDeviceFirmwareVersion);

    return S_OK;
}

HRESULT CDevice::SendRenderedDataToDevice(const BYTE* pbBitmapData, DWORD cbBitmapData, DWORD dwRenderFlags)
{
    HRESULT hr = DeviceSpecificDisplayBitmap(pbBitmapData, cbBitmapData, dwRenderFlags);
    return hr;
}

HRESULT CDevice::HandleDeviceEvent(const CDevice::DeviceEvent DeviceEvent) // Such as a Next or Previous button
{
    HRESULT hr = E_FAIL;

    if (NULL != g_pDataManager)
    {
        hr = g_pDataManager->HandleDeviceEvent(DeviceEvent);
    }

    return hr;
}

